package com.gxgeek.spring.security.web.aspect;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.stereotype.Component;

import java.util.Date;

/**
 * @author gaoxing
 * @create 2017-10-09 上午10:05
 */
@Component
@Aspect
public class TimeAspect {

    @Pointcut("execution(* com.gxgeek.spring.security.web.controller.UserController.*(..))")
    public void userControllerAspect() { }



//    @Around("userControllerAspect()")
    public Object handleControllerMethod(ProceedingJoinPoint pjp) throws Throwable {
        System.out.println("time aspect start");

        Object[] args = pjp.getArgs();
        for (Object arg : args) {
            System.out.println("arg is "+arg);
        }
        //计时
        long start = new Date().getTime();
        //执行方法
        Object object = pjp.proceed();

        System.out.println("time aspect 耗时:"+ (new Date().getTime() - start));
        System.out.println("time aspect end");

        return object;

    }
}